<?php
$moduleId = $this->module->getId();
$cs = Yii::app()->getClientScript();
$cs->registerCssFile($this->getModule()->assetsUrl.'/css/question.css');
?>

<form action="" name="Label" method="post">
<div class="labels">
    <div class="selected_cat">Category &raquo; 
        
            <?php foreach($allChilds as $child){?>
                <span class="cat_child" id="cat_child_<?php echo $child->id;?>">
                  <input type="checkbox" name="label[<?php echo $child->name;?>]" value="<?php echo $child->id ?>" id="main_check_<?php echo $child->id;?>"  />
                  <label for="main_check_<?php echo $child->id;?>" val=<?php echo $child->id;?>><?php echo $child->name;?></label>
                </span>
            <?php }?>
        
    </div>
    <div class="labels_parent">
        <ul>
        <?php          
         foreach($rootCats as $rootCat)
         {   
         ?>
        <li width="200px" id="parent_label[<?php echo $rootCat->id;?>]" val=<?php echo $rootCat->id;?> is_leaf=<?php echo ($rootCat->parent_id==null)? 0:1  ?> >
            <label >
                <?php echo $rootCat->name; ?>
            </label>
        </li>
        <?php
        }
        ?>
        </ul>
    </div>
    
    
    <div class="labels_child">
        <?php 
             
         foreach($rootCats as $rootCat)
         {   
         ?>
            <ul id="childs_label_<?php echo $rootCat->id;?>">
                <?php 
                $childs=$rootCat->getChilds($rootCat->id);    
                foreach($childs as $child)
                {
                ?>
                    <li is_leaf=<?php echo ($child->parent_id==null)? 0:1  ?> val=<?php echo $child->id;?>>
                        <label  ><?php echo $child->name;?></label>
                    </li>
                
                <?php
                }
                ?>
            </ul>
         <?php
        }
        ?>
        
    </div>
</div>


<div class="btn_continue"><input type="submit" name="Submit_label" value="Continue"></div>
</form>


 
 <script type="text/javascript">
$(function() {
   $(".labels_parent ul li ").click(function(){
       var val=$(this).attr('val');
       
       $(".labels_parent ul li ").css('background-color','#fff');
       $(".labels_child ul li ").css('background-color','#fff');
       $(this).css('background-color','#ddd');      
       
       $(".labels_child ul").hide();
       $("#childs_label_"+val+"").show();
   }) ;
   $(".labels_child ul li ").click(function(){
       var val=$(this).attr('val');
       
       $(".labels_child ul li ").css('background-color','#fff');
       $(this).css('background-color','#ddd');
   }) ;
   
   $(".labels li").click(function(){
       var is_leaf= $(this).attr('is_leaf');
       if(is_leaf==1) {
           $(".btn_continue").show();
           var val= $(this).attr('val');
           $(".cat_child").hide();
           $("#cat_child_"+val+"").show();
           
           $(".cat_child input").attr('checked', false);
           $("#main_check_"+val+"").attr('checked', true);
       }
       else $(".btn_continue").hide();
   })  ;
   

      
});
</script>